package com.nnnu.wsnackshop.result;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.nnnu.wsnackshop.constant.StatusCodeConstants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {

    private Integer code; //状态码
    private String msg; //提示信息
    private T data; //数据

    public static <T> @NotNull Result<T> success() {
        Result<T> result = new Result<>();
        result.code = StatusCodeConstants.SUCCESS;
        return result;
    }

    public static <T> @NotNull Result<T> success(T data, String msg) {
        Result<T> result = new Result<>();
        result.code = StatusCodeConstants.SUCCESS;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static <T> @NotNull Result<T> success(Integer code, T data, String msg) {
        Result<T> result = new Result<>();
        result.code = code;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static <T> @NotNull Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.code = StatusCodeConstants.SUCCESS;
        result.data = data;
        return result;
    }


    public static <T> @NotNull Result<T> success(String msg) {
        Result<T> result = new Result<>();
        result.code = StatusCodeConstants.SUCCESS;
        result.msg = msg;
        return result;
    }


    public static <T> @NotNull Result<T> error(Integer code, String msg) {
        Result<T> result = new Result<>();
        result.msg = msg;
        result.code = code;
        return result;
    }

    public static <T> @NotNull Result<T> success(Integer code, String msg) {
        return error(code, msg);
    }

}
